using System;
using Tao.OpenGl;
using Tao.Sdl;
using Dida;
using Dida.Dbg;

class App
{
	static DebugMesh dbgMesh;

	public static void Main(string[] args)
	{
		try
		{
			UnmanagedResourceManager.Init(0);
			SdlBinding.Init(640, 480);

			dbgMesh = DebugDraw.CreateDebugMesh();
			dbgMesh.Begin();
			dbgMesh.AddTriangle(
				new Vector3D[]
				{
					new Vector3D(0,0,0),
					new Vector3D(5,-5,0),
					new Vector3D(0,0,5),
				});
			dbgMesh.End();

			SdlBinding.Run(OnIdle);
		}
		catch (Exception e)
		{
		}
		finally
		{
			SdlBinding.Free();
			UnmanagedResourceManager.Free();
		}		
	}

	static void OnIdle(float timeDelta)
	{
		Viewpoint viewpt = Viewpoint.CreateOverview(new Vector3D(0, 0, 0),
			Rotation.Deg2Rad(40), Rotation.Deg2Rad(-20), 10, 1);
		viewpt.CalcMatrices(640 / 480.0f);

		DebugDraw.BeginDrawing(viewpt);
		DebugDraw.DrawBox(new Box(-1,-1,-1,1,1,1),0x000000ff);
		DebugDraw.DrawDebugMesh(dbgMesh);
		DebugDraw.EndDrawing();
	}
}